home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / Timing / touch110.lha / touch / touch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-29  |  3.3 KB  |  127 lines

  1.  
  2. /************************************************************************/
  3. /*                  Touch V1.10                */
  4. /* Written and Copyright ©1993 by Dave Schreiber.  All Rights Reserved. */
  5. /*                                    */
  6. /* This is an Amigaized version of the Unix utility with the same name. */
  7. /* Usage:                                */
  8. /*    Touch FILE/A/M,NOCREATE=-V/S                    */
  9. /*                                    */
  10. /* Touch sets the date/time of all specified files to the current date    */
  11. /* and time.  This uses Workbench 2.0 wildcard pattern-matching, so all */
  12. /* 2.0 wildcards are valid.                        */
  13. /*                                    */
  14. /* To compile (SAS/C V6.0):                                             */
  15. /*    smake                                */
  16. /*                                    */
  17. /* Version history:                            */
  18. /*    1.10 - If a file is specified but does not exist, touch now    */
  19. /*         creates it (unless the NOCREATE flag is specified).        */
  20. /*         July 28, 1993                        */
  21. /*    1.01 - Fixed an enforcer hit                    */
  22. /*         July 17, 1993                        */
  23. /*    1.00 - Initial Release.                        */
  24. /*         July 17, 1993                        */
  25. /************************************************************************/
  26.  
  27. #include <exec/types.h>
  28. #include <dos/dos.h>
  29. #include <exec/memory.h>
  30.  
  31. #include <clib/dos_protos.h>
  32. #include <clib/exec_protos.h>
  33.  
  34. char trashBuf[512];
  35.  
  36. struct RDArgs ra=
  37. {
  38.    {NULL,0,0},
  39.    NULL,
  40.    trashBuf,
  41.    512,
  42.    "FILE/A/M,NOCREATE=-V/S"
  43. };
  44.  
  45. char *version="$VER: Touch V1.10 (28.7.93)";
  46.  
  47. char *copyright="Copyright 1993 by Dave Schreiber.  All Rights Reserved";
  48.  
  49. int __main(void);
  50. void touchFiles(char *pattern,BOOL);
  51.  
  52. int __main(void)
  53. {
  54.    ULONG args[3];
  55.    char **filenames;
  56.    int c;
  57.    BOOL createFiles=TRUE;
  58.  
  59.    args[0]=args[1]=NULL;
  60.    /*Get the list of filenames/patterns*/
  61.    ReadArgs("FILE/A/M,NOCREATE=-V/S",args,&ra);
  62.    filenames=(char **)args[0];
  63.    if(args[1])
  64.       createFiles=FALSE;
  65.  
  66.    /*Update the date and time of each name matching any given pattern*/
  67.    if(filenames!=NULL)
  68.       for(c=0;filenames[c]!=NULL;c++)
  69.      touchFiles(filenames[c],createFiles);
  70.  
  71.    /*Free resources allocated by ReadArgs()*/
  72.    FreeArgs(&ra);
  73.  
  74.    return 0;
  75. }
  76.  
  77. void touchFiles(char *pattern,BOOL createFiles)
  78. {
  79.    struct AnchorPath *anchor;
  80.    struct DateStamp currentDate;
  81.    BPTR origDir;
  82.    char temp[514];
  83.  
  84.    /*Allocate a structure required by MatchFirst()*/
  85.    anchor=(struct AnchorPath *)AllocMem(sizeof(struct AnchorPath),MEMF_CLEAR);
  86.    if(anchor==NULL)
  87.       return;
  88.  
  89.    /*Get first file*/
  90.    if(MatchFirst(pattern,anchor)==0)
  91.    {
  92.       /*Update date/time*/
  93.       origDir=CurrentDir(anchor->ap_Current->an_Lock);
  94.       DateStamp(¤tDate);
  95.       SetFileDate(anchor->ap_Info.fib_FileName,¤tDate);
  96.       CurrentDir(origDir);
  97.  
  98.       /*Update the rest of the files*/
  99.       while(MatchNext(anchor)==0)
  100.       {
  101.      origDir=CurrentDir(anchor->ap_Current->an_Lock);
  102.      DateStamp(¤tDate);
  103.      SetFileDate(anchor->ap_Info.fib_FileName,¤tDate);
  104.      CurrentDir(origDir);
  105.       }
  106.    }
  107.    else
  108.       /*If no files were found matching the pattern, check to see*/
  109.       /*if it actually a pattern, or just a regular filename*/
  110.       if(createFiles && ParsePatternNoCase(pattern,temp,514)==0)
  111.       {
  112.      /*If its a filename, and the user hasn't disallowed the creation*/
  113.      /*of unfound files, then create a file of the given name.*/
  114.      BPTR file;
  115.      file=Open(pattern,MODE_NEWFILE);
  116.      if(file!=NULL)
  117.         Close(file);
  118.       }
  119.  
  120.    /*All done*/
  121.    MatchEnd(anchor);
  122.    FreeMem(anchor,sizeof(struct AnchorPath));
  123.  
  124.    return;
  125. }
  126.  
  127.